function PDPageInfo() {
    this.m_fWidth = 0;
    this.m_fHeight = 0;
    this.m_nRotate = 0;
    this.m_Matrix = null;
    this.m_nBgClr = 0xffffffff;
    
    this.m_interForm = null;

    this.ParseFromBin = function (rd) {
       
        this.m_fWidth = rd.readFloat32();
        this.m_fHeight = rd.readFloat32();
        this.m_nRotate = rd.readInt32();

        var a = rd.readFloat32();
        var b = rd.readFloat32();
        var c = rd.readFloat32();
        var d = rd.readFloat32();
        var e = rd.readFloat32();
        var f = rd.readFloat32();
        this.m_Matrix = new PDMatrix();
        this.m_Matrix.Set(a, b, c, d, e, f);

        this.m_nBgClr = rd.readUint32();

    }
}
function PDDoc(){
	this.countPages=null;//文档所包含的页面数
	this.fontInfo=[];//fontInfo对象数组
	this.docId=null;//doc对象ID
	this.docTitle=null;//标题
	this.docVersion=null;//版本号
//	this.pCreator=null;//PDF生成的临时编号
	this.bookmarkTree = null;
	this.pdPages=[];


    this.m_lsPageInfo = [];
    this.m_nVersion = 1;//binary data version
	this.m_fontPath = null;
	this.m_imgPath = null;
	
	this.m_substFamily = ["Arial","Book Antiqua","Calibri","Courier","Dotum","Dotumche","SimSun","Microsoft JHengHei","Microsoft YaHei","Microsoft YiBaiti","MingLiu","Estrangelo Edessa",
						  "STHeiti","STKaiti","STSong","STFangsong","SimHei","KaiTi","LiSu","YouYuan","STXinwei","Helvetica","Gulim",
		                  "Sylfaen","Aharoni","David","FrankRuehl","Gisha","Levenim MT","Miriam","Narkisim","Rod","Microsoft New Tai Lue","Ebrima","Angsana New","Browallia New",
		                  "Cordia New","DilleniaUPC","EucrosiaUPC","FreesiaUPC","IrisUPC","JasmineUPC","KodchiangUPC","Leelawadee","LilyUPC","Latha","Vijaya","Gautami","Vari","Meiryo",
		                  "MS Gothic","MS Mincho","Plantagenet Cherokee","Shonar Bangla","Vrinda","Mongolian Baiti","Kartika","MV Boli","DokChampa","Lao UI","Tahoma","Lucida Sans","Times New Roman",
		                  "Cambira","Candara","Comic Sans MS","Consolas","Constatia","Corbel","Georgia","Impact","Segoe Print","Verdana","Algerian","Bell MT","Berlin Sans FB","Bodorni MT","Britannic",
		                  "Broadway","Californian FB","Calisto MT","Castellar","Centaur","Century","Chiller","Colonna MT","Cooper","Curlz MT","Elephant","Fixedsys","Forte","Garamond","Gigi","Gill Sans",
		                  "Goudy Old Style","Goudy Stout","Haettenschweiler","Harrinngton","Latin","Lucida Bright","Maneto","Mistral","Modern","Niagara Engraved","Onyx","Rage","Ravie","Rockwell","Perpetua",
		                  "Roman","Script","Stencil","System","Terminal","Vivaldi","Raavi","Euphemia","Shruti","DaunPenh","Symbol","MS Outlook","Webdings","Wingdings","Batang","Tunga","Andalus","Nyala","Kalinga"
						 ];

	this.m_bookMarkTreeData = null;
	
	var pDDoc=this;
/*
	this.SetPCreator=function(pCreator){
		this.pCreator=pCreator;
	}
	this.GetPCreator=function(){
		return this.pCreator;
	}
*/

	this.SetDocTitle=function(docTitle){
		this.docTitle=docTitle;
	}
	this.GetDocTitle=function(){
		return this.docTitle;
	}
	this.SetDocVersion=function(docVersion){
		this.docVersion=docVersion;
	}
	this.GetDocVersion=function(){
		return this.docVersion;
	}
	this.GetPageInfo = function (iPage) {
	    return this.m_lsPageInfo[iPage];
	}
	this.SetDocId=function(docId){
		this.docId=docId;
	}
	this.GetDocId=function(){
		return this.docId;
}
	this.SetFontInfo=function(id,fontInfo){
		this.fontInfo=[id,fontInfo];
	}
	this.GetFontInfo=function(){
		return this.fontInfo;
	}
	
    this.GetPageSize = function (index) {
        //    var w = this.pageSize[index * 2];
        //    var h = this.pageSize[index * 2 + 1];
        var s = this.m_lsPageInfo[index];
        return [s.m_fWidth, s.m_fHeight];
    }
    
	this.SetCountPages = function (countPages) {
	    this.countPages = countPages;
	}
	this.GetCountPages=function(){
		return this.countPages;
	}

	this.ParseFromBin = function (rd) {
	    this.m_nVersion = rd.readInt16();
	    var nPage = rd.readInt32();
	    for (var i = 0; i < nPage; i++) {
	        var info = new PDPageInfo();
	        info.ParseFromBin(rd);
	        this.m_lsPageInfo.push(info);
	    }
	    this.countPages = nPage;

	 
	    var nFont = rd.readInt32();
	    for (var j = 0; j < nFont; j++) {
	        var info = new FontInfo(this, this.m_imgPath);
	        info.ParseFromBin(rd);
	        this.fontInfo.push(info);
	    }

//	    var nHasBookMark = rd.readByte();
//	    if (nHasBookMark == 1)
//	    {
//	    	this.m_bookMarkTreeData = new PDBookMarkTreeData();
//	    	this.m_bookMarkTreeData.praseBookMarkTreeData(rd);
//	    }
//		
//		var interForm = new PDInterFormData(this);
//		interForm.parseInterFormData(rd);
//		
//		this.m_interForm = interForm;
	};
	
	/*===============================update   start =====================================*/
   this.ParseJsonToDoc = function(arrayData){
	   if(arrayData.length == 0)return;
	   
	   var pageData = arrayData[0];
	   var pagesSize=[];
	   var oneSize;
	   for(var i = 0; i < pageData.length;i++){
		   oneSize = new Object();
		   oneSize.w = parseFloat(pageData[i][0]);
		   oneSize.h = parseFloat(pageData[i][1]);
		   oneSize.rotate = pageData[i][2];
		   pagesSize.push(oneSize);
	   }
	   pDDoc.SetPageSizeArr(pagesSize);
	   pDDoc.SetCountPages(pagesSize.length);
	   var fontData = arrayData[1];
	   for(var i = 0; i < fontData.length;i++){
		   var fontInfo = fontData[i];
		   pDDoc.AddFont(fontInfo);
	   }
	   
	   var bookmarkData = arrayData[2];
   }
   
  this.GetFontInfoByID = function (fontId) {//获取指定ID对象
	    for (var i = 0; i < this.fontInfo.length; i++) {
	        if (fontId == this.fontInfo[i].GetId()) {
	            return this.fontInfo[i];
	        }
	    }
	    return null;
	}

  this.GetFontInfoByFontFace = function(fontFace){
	   for (var i = 0; i < this.fontInfo.length; i++) {
	        if (fontFace == this.fontInfo[i].fontFace) {
	            return this.fontInfo[i];
	        }
	    }
	    return null;
  }

  this.GetLocalSubstFontFamily = function(fontInfo){
	  var fontFamily = fontInfo.family;
	  if(fontFamily.length == 0)fontFamily = fontInfo.fontname;
	  if(fontFamily.length > 0){
		  for(var i = 0; i < this.m_substFamily.length; i++){
			  var lawIsFont = this.m_substFamily[i].toLowerCase();
			  var noSpaceIsFont = lawIsFont.replace(/[ ]/g,"");
			  var lawFontFamily = fontFamily.toLowerCase();
			  var noSpaceFontFamily = lawFontFamily.replace(/[ ]/g,"");
			  if(lawIsFont.indexOf(lawFontFamily) != -1 || lawFontFamily.indexOf(lawIsFont) != -1 || noSpaceIsFont.indexOf(noSpaceFontFamily) != -1 ||  noSpaceFontFamily.indexOf(noSpaceIsFont) != -1){
				  fontFamily = this.m_substFamily[i];
				  break;
			  }
		  }
	  }
	  return fontFamily;
  }
	
  /*===============================update end=====================================*/ 
	
	this.DestroyPageObjList=function(){//销毁所有
    	for(var p=0;p<this.pdPages.length;p++){
    		this.pdPages[p] = null;
    	}
    	this.pdPages=null;
	}
	this.DestroyPageObjByIndex=function(pageId){//销毁指定对象
		for(var p=0;p<this.pdPages.length;p++){
    		var page_obj=this.pdPages[p];
    		if(pageId==text_obj.GetPageId()){
    			this.DeletePage(p);
    			break;
    		}
    	}
	}
	
	this.GetPageByID = function (pageId) {//根据ID获取页面对象
	    for (var i = 0; i < this.pdPages.length; i++) {
	        if (pageId == this.pdPages[i].GetPageId()) {
	            return this.pdPages[i];
	        }
	    }
	    return null;
	
	}
	this.GetPageByIndex = function (index) {//根据数组下标index获取页面对象
	    if (index < 0 && index >= this.pdPages.length) return null;
	    return this.pdPages[index];
	}


	this.CreatePageFormBin = function (index, rd) {
	    var pdPage = new PDPage();
	    pdPage.SetIndex(index);
	    pdPage.SetPDDoc(this);
	    if(rd != null)pdPage.ParseFromBin(rd);
	    var pageInfo = this.m_lsPageInfo[index];
	    pdPage.SetSize(pageInfo.m_fWidth, pageInfo.m_fHeight);
	    pdPage.m_PageMatrix = pageInfo.m_Matrix;
	    this.pdPages[index] = pdPage;
	}



	
	
}
